﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WindowsFormsApplication2.CLASS;
using WindowsFormsApplication2.All_FORMS.Lavlah_forms;

namespace WindowsFormsApplication2.All_FORMS.Bvrtgel_forms
{
    public partial class frmRegWorker : Form
    {
        string _Id;
        public enum clicktype
        {
            Add = 1,
            Edit = 2,

        }

        clicktype ConsructorType = new clicktype();
        public frmRegWorker()
        {
            InitializeComponent();
            ConsructorType = clicktype.Add;
        }
        public frmRegWorker(Worker _work)
        {
            ConsructorType = clicktype.Edit;
            InitializeComponent();
             _Id= _work.WorkerId ;
            cusFname.Text = _work.WorkerFName;
            cusLname.Text = _work.WorkerLName;
            cusRd.Text = _work.WorkerRd;
            cusaddress.Text = _work.WorkerAddress;
            cusphone.Text = _work.WorkerPhone;
            comboBox1.Text = _work.WorkerType;
            cuspass.Text = _work.WorkerPass;


        }

        private void grboxXT_Enter(object sender, EventArgs e)
        {

        }

       

        private void btnXTadd_Click(object sender, EventArgs e)
        {
            if (ConsructorType == clicktype.Add)
            {
                Worker.AddFunction(_Id, cusFname.Text, cusLname.Text, cusRd.Text, cusaddress.Text, cusphone.Text, comboBox1.Text,cuspass.Text);
                MessageBox.Show("Нэмэх үйлдэл");
                frmWorker frm = new frmWorker();
                frm.dataGridViewWorker.DataSource = DBTools.selecQryTmp("Select *from Worker");

            }
            else
            {

                Worker.EditFunction(_Id, cusFname.Text, cusLname.Text, cusRd.Text, cusaddress.Text, cusphone.Text, comboBox1.Text, cuspass.Text);
                MessageBox.Show("Засах үйлдэл");
                frmWorker frm1 = new frmWorker();
                frm1.dataGridViewWorker.DataSource = DBTools.selecQryTmp("Select *from Worker");

            }
        }

        private void btnXTback_Click(object sender, EventArgs e)
        {
            frmWorker frm1 = new frmWorker();
            frm1.dataGridViewWorker.DataSource = DBTools.selecQryTmp("Select *from Worker");

            this.Close();
        }
    }
}
